<%--
  Created by IntelliJ IDEA.
  User: cc又瘦啦
  Date: 2021/12/20
  Time: 9:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="cc" uri="http://java.sun.com/jstl/core_rt" %>
<html>
<head>
    <title>列表</title>
    <script src="${pageContext.request.contextPath}/static/js/jquery-3.4.1.js"></script>
</head>
<body>

<form action="./list" method="post">

    品牌:
    <span id="bid"></span><br><br>
    类型:
    <span id="tid"></span>

    <input type="hidden" name="pageNum">
    <input type="hidden" name="pageSize">

    <input type="submit" value="提交">

</form>

<table border="1">

    <tr>
        <cc:forEach items="${list}" var="gl">

                <td>
                    <img src="/pic/${gl.goodsImg}" width="80" height="80">
                    ${gl.goodsAffiliation}
                    ${gl.goodsName}
                </td>

        </cc:forEach>
    </tr>

    <tr>
        <td colspan="12">
            <button onclick="page(${page.pageNum==1?1:page.pageNum-1})">上一页</button>
            <cc:forEach items="${page.navigatepageNums}" var="p">
                <button onclick="page(${p})">${p}</button>
            </cc:forEach>
            <button onclick="page(${page.pageNum==page.pages?page.pages:page.pageNum+1})">下一页</button>
        </td>
    </tr>

</table>

<input type="button" value="新增" onclick="addGoodsMethod()">

<script>

    $("[name='brandId']").val(([${pojo.brandId}]));
    $("[name='typeId']").val([${pojo.typeId}]);

    function addGoodsMethod() {

        location="./toAdd";
    }
    
    function page(cur){

        $("[name='pageNum']").val(cur);
        $("form").submit();

    }

    //追加品牌
    // 伟星: <input type="radio" name="brandId">
    $.post("getBrandList",function (brandList) {

        for (var brand of brandList) {
            $("#bid").append(brand.brandName+": <input type=\"radio\" name=\"brandId\" value='"+brand.brandId+"'>");
        }

    })

    $.post("getTypeList",function (typeList) {

        for (var type of typeList) {
            $("#tid").append(type.typeName+": <input type=\"radio\" name=\"typeId\" value='"+type.typeId+"'>");
        }

    })

</script>


</body>
</html>
